using System;
using System.Collections.Generic;
using System.Text;
using WozLib.UI.Ink.SketchElements;

namespace WozLib.UI.Ink.SketchObjects
{
  public static class ISketchObjectFactory
  {
    public static ISketchObject FromWozObject(SketchObject wozObject, SketchObjectRegistry wozObjectRegistry)
    {
      ISketchObject iWozObject = FromWozObject(wozObject);

      // if we do not the IWozObject we just created is not registered, register it
      if (!wozObjectRegistry.ContainsObject(iWozObject.WozID))
      {
        wozObjectRegistry.RegisterObjectWithExisitingId(iWozObject);
      }

      return iWozObject;
    }

    public static ISketchObject FromWozObjectNewID(SketchObject wozObject, SketchObjectRegistry wozObjectRegistry)
    {
      ISketchObject iWozObject = FromWozObject(wozObject);

      // if we do not the IWozObject we just created is not registered, register it
        wozObjectRegistry.RegisterObject(iWozObject);

      return iWozObject;
    }

    private static ISketchObject FromWozObject(SketchObject wozObject)
    {
      ISketchObject iWozObject = null;

      if (wozObject is StrokeSketchObject)
      {
        iWozObject = SketchStroke.FromStrokeWozObject(wozObject as StrokeSketchObject);
      }
      else if (wozObject is LineSketchObject)
      {
        iWozObject = SketchLine.FromLineWozObject(wozObject as LineSketchObject);
      }
      else if (wozObject is RectangleSketchObject)
      {
        iWozObject = SketchRectangle.FromRectangleWozObject(wozObject as RectangleSketchObject);
      }
      else if (wozObject is EllipseSketchObject)
      {
        iWozObject = SketchEllipse.FromEllipseWozObject(wozObject as EllipseSketchObject);
      }
      else if (wozObject is TextSketchObject)
      {
        iWozObject = SketchText.FromTextWozObject(wozObject as TextSketchObject);
      }
      else if (wozObject is ButtonSketchObject)
      {
        iWozObject = SketchButton.FromButtonWozObject(wozObject as ButtonSketchObject);
      }
      else
      {
        // I don't have a concrete IWozObject to create
        throw new Exception("IWozObjectFactory don't know what you are talking about");
      }

      return iWozObject;
    }
  }
}
